<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
$ui = new UI();
include( "member/news.php" );
$tpl = new Template2();
global $curruser;
if ( $curruser['enabled'] == 0 || $curruser['enabled'] == 2 )
{
    $ui->showErrorPage( "<p class=error>帐号已被暂停使用</p>" );
    exit();
}
$userlist = GetUserList( $curruser['id'] );
if ( $userlist == "" )
{
    $ui->showErrorPage( "<p>还没有建立会员！</p>" );
    exit();
}
$rs = getdb( "select * from lotto where open>='".date( "Y-m-d" )."' order by open" );
if ( $rs->eof )
{
    $ui->showErrorPage( "<p class=error>目前没有可以下注期数！</p>" );
    exit();
}
$open = $rs->f['open'];
$round = $rs->f['round'];
$lotto_id = $rs->f['id'];
$opnumber = $rs->f['n1'];
$rs->close();
$conf = new Config();
$stopbet = $conf->get( "linebet" );
if ( date( "Y-m-d" ) < $open )
{
    $startmode = "disabled";
}
else if ( date( "Y-m-d" ) == $open )
{
    if ( $stopbet <= date( "Hi" ) && 0 < $opnumber )
    {
        $startmode = "disabled";
    }
    else if ( date( "Hi" ) <= $conf->get( "startbet" ) )
    {
        $startmode = "disabled";
    }
}
$t1 = strtotime( $open." ".$stopbet );
$dt = date( "Y-m-d" );
$tpl->Set( "timestap", $t1 - systime( ) );
$tpl->set( "phptime", systime( ) );
$tpl->set( "open", $open );
$tpl->set( "round", d3( $round ) );
$tpl->set( "dt", $dt );
$tpl->set( "lotto_id", $lotto_id );
$userid = $curruser['id'];
$acl = $curruser['acl'];
$userlist = GetUserList( $userid );
if ( $userlist == "" )
{
    exit( "Not Users!" );
    exit();
}
if ( $acl == 2 )
{
	$rs48 = getdb( "select sum(amount*mpercent/100) from bet where lotto_id=".$lotto_id." and bettype=48 and user_id in (".$userlist.") and rame in (0,9)" );
    $rs8 = getdb( "select sum(amount*mpercent/100) from bet where lotto_id=".$lotto_id." and bettype=8 and user_id in (".$userlist.") and rame in (0,9)" );
    $rs9 = getdb( "select sum(amount*mpercent/100) from bet where lotto_id=".$lotto_id." and bettype in (9,33) and user_id in (".$userlist.") and rame in (0,9)" );
    $rs7 = getdb( "select sum(amount*mpercent/100) from bet where lotto_id=".$lotto_id." and bettype=7 and user_id in (".$userlist.") and rame in (0,9)" );
    $rs10 = getdb( "select sum(amount*mpercent/100) from bet where lotto_id=".$lotto_id." and bettype in (10,32) and user_id in (".$userlist.") and rame in (0,9)" );
    $rs11 = getdb( "select sum(amount*mpercent/100) from bet where lotto_id=".$lotto_id." and bettype=11 and user_id in (".$userlist.") and rame in (0,9)" );
}
else if ( $acl == 3 )
{
	$rs48 = getdb( "select sum(amount*percent2/100) from bet where lotto_id=".$lotto_id." and bettype=48 and user_id in (".$userlist.") and rame in (0,9)" );
    $rs8 = getdb( "select sum(amount*percent2/100) from bet where lotto_id=".$lotto_id." and bettype=8 and user_id in (".$userlist.") and rame in (0,9)" );
    $rs9 = getdb( "select sum(amount*percent2/100) from bet where lotto_id=".$lotto_id." and bettype in (9,33) and user_id in (".$userlist.") and rame in (0,9)" );
    $rs7 = getdb( "select sum(amount*percent2/100) from bet where lotto_id=".$lotto_id." and bettype=7 and user_id in (".$userlist.") and rame in (0,9)" );
    $rs10 = getdb( "select sum(amount*percent2/100) from bet where lotto_id=".$lotto_id." and bettype in (10,32) and user_id in (".$userlist.") and rame in (0,9)" );
    $rs11 = getdb( "select sum(amount*percent2/100) from bet where lotto_id=".$lotto_id." and bettype=11 and user_id in (".$userlist.") and rame in (0,9)" );
}
else if ( $acl == 4 )
{
    $rs48 = getdb( "select sum(amount*percent3/100) from bet where lotto_id=".$lotto_id." and bettype=48 and user_id in (".$userlist.") and rame in (0,9)" );
    $rs8 = getdb( "select sum(amount*percent3/100) from bet where lotto_id=".$lotto_id." and bettype=8 and user_id in (".$userlist.") and rame in (0,9)" );
    $rs9 = getdb( "select sum(amount*percent3/100) from bet where lotto_id=".$lotto_id." and bettype in (9,33) and user_id in (".$userlist.") and rame in (0,9)" );
    $rs7 = getdb( "select sum(amount*percent3/100) from bet where lotto_id=".$lotto_id." and bettype=7 and user_id in (".$userlist.") and rame in (0,9)" );
    $rs10 = getdb( "select sum(amount*percent3/100) from bet where lotto_id=".$lotto_id." and bettype in (10,32) and user_id in (".$userlist.") and rame in (0,9)" );
    $rs11 = getdb( "select sum(amount*percent3/100) from bet where lotto_id=".$lotto_id." and bettype=11 and user_id in (".$userlist.") and rame in (0,9)" );
}
else if ( $acl == 5 )
{
    $rs48 = getdb( "select sum(amount*percent4/100) from bet where lotto_id=".$lotto_id." and bettype=48 and user_id in (".$userlist.") and rame in (0,9)" );
    $rs8 = getdb( "select sum(amount*percent4/100) from bet where lotto_id=".$lotto_id." and bettype=8 and user_id in (".$userlist.") and rame in (0,9)" );
    $rs9 = getdb( "select sum(amount*percent4/100) from bet where lotto_id=".$lotto_id." and bettype in (9,33) and user_id in (".$userlist.") and rame in (0,9)" );
    $rs7 = getdb( "select sum(amount*percent4/100) from bet where lotto_id=".$lotto_id." and bettype=7 and user_id in (".$userlist.") and rame in (0,9)" );
    $rs10 = getdb( "select sum(amount*percent4/100) from bet where lotto_id=".$lotto_id." and bettype in (10,32) and user_id in (".$userlist.") and rame in (0,9)" );
    $rs11 = getdb( "select sum(amount*percent4/100) from bet where lotto_id=".$lotto_id." and bettype=11 and user_id in (".$userlist.") and rame in (0,9)" );
}
if ( 2 < $acl )
{
    $rss48 = getdb( "select sum(amount*percent".$acl."/100) from bet2 where lotto_id=".$lotto_id." and uperid".$acl."=".$userid." and bettype=48 and rame in (0,9)" );
    $rss8 = getdb( "select sum(amount*percent".$acl."/100) from bet2 where lotto_id=".$lotto_id." and uperid".$acl."=".$userid." and bettype=8 and rame in (0,9)" );
    $rss9 = getdb( "select sum(amount*percent".$acl."/100) from bet2 where lotto_id=".$lotto_id." and uperid".$acl."=".$userid." and bettype in (9,33) and rame in (0,9)" );
    $rss7 = getdb( "select sum(amount*percent".$acl."/100) from bet2 where lotto_id=".$lotto_id." and uperid".$acl."=".$userid." and bettype=7 and rame in (0,9)" );
    $rss10 = getdb( "select sum(amount*percent".$acl."/100) from bet2 where lotto_id=".$lotto_id." and uperid".$acl."=".$userid." and bettype in (10,32) and rame in (0,9)" );
    $rss11 = getdb( "select sum(amount*percent".$acl."/100) from bet2 where lotto_id=".$lotto_id." and uperid".$acl."=".$userid." and bettype=11 and rame in (0,9)" );
}
$rs48x = getdb( "select sum(amount) from bet2 where lotto_id=".$lotto_id." and bettype=48 and user_id=".$userid." and rame in (0,9)" );
$rs8x = getdb( "select sum(amount) from bet2 where lotto_id=".$lotto_id." and bettype=8 and user_id=".$userid." and rame in (0,9)" );
$rs9x = getdb( "select sum(amount) from bet2 where lotto_id=".$lotto_id." and bettype in (9,33) and user_id=".$userid." and rame in (0,9)" );
$rs7x = getdb( "select sum(amount) from bet2 where lotto_id=".$lotto_id." and bettype=7 and user_id=".$userid." and rame in (0,9)" );
$rs10x = getdb( "select sum(amount) from bet2 where lotto_id=".$lotto_id." and bettype in (10,32) and user_id=".$userid." and rame in (0,9)" );
$rs11x = getdb( "select sum(amount) from bet2 where lotto_id=".$lotto_id." and bettype=11 and user_id=".$userid." and rame in (0,9)" );
$rs = getdb( "select * from rate5a where lotto_id=".$lotto_id );
if ( $rs->eof )
{
    diemsg( "<p class=error>系统目前维护中，请稍後！</p>" );
}
$tpl->set( "r9_1", $rs->f['r9_1'] );
$tpl->set( "r9_2", $rs->f['r9_2'] );
$tpl->set( "r7_1", $rs->f['r7_1'] );
$tpl->set( "r10_1", $rs->f['r10_1'] );
$tpl->set( "r10_2", $rs->f['r10_2'] );
$tpl->set( "r11_1", $rs->f['r11_1'] );
$rs = getdb( "select * from rate8 where lotto_id={$lotto_id} AND disk = 1 LIMIT 1" );
if ( $rs->eof )
{
    $ui->showErrorPage( "<p class=error>系统目前维护中，请稍後！</p>" );
    exit();
}
else
{
    $rate8Arr = array();
    $temp = array();
    $i = 1;
    while ( $i < 50 )
    {
        $rate8Arr["r29_{$i}"] = floatval( $rs->f["r".d2( $i )] );
        ++$i;
    }
    $tpl->set( $rate8Arr );
}
$rs->close();
$rs = getdb( "select * from rate9 where lotto_id={$lotto_id} AND disk = 1 LIMIT 1" );
if ( $rs->eof )
{
    $ui->showErrorPage( "<p class=error>系统目前维护中(四全中无赔率)，请稍後！</p>" );
    exit();
}
else
{
    $rate9Arr = array();
    $i = 1;
    while ( $i < 50 )
    {
        $rate9Arr["r9_{$i}"] = intval( $rs->f["r".d2( $i )] );
        ++$i;
    }
    sort( $rate9Arr );
}
$rs->close();
sort( $rate8Arr );
$tpl->set( array( "r8_hi" => sprintf( "%01.2f", $rate8Arr[48] ), "r8_lo" => sprintf( "%01.2f", $rate8Arr[0] ) ) );
$tpl->set( array( "r48_hi" => sprintf( "%01.2f", $rate9Arr[48] ), "r48_lo" => sprintf( "%01.2f", $rate9Arr[0] ) ) );
$tpl->set( "b23", "" );
if ( 2 < $acl )
{
	$tpl->set( "money48", $rs48->f[0] + $rss48->f[0] - $rs48x->f[0] - 0 );
    $tpl->set( "money08", $rs8->f[0] + $rss8->f[0] - $rs8x->f[0] - 0 );
    $tpl->set( "money09", $rs9->f[0] + $rss9->f[0] - $rs9x->f[0] - 0 );
    $tpl->set( "money07", $rs7->f[0] + $rss7->f[0] - $rs7x->f[0] - 0 );
    $tpl->set( "money10", $rs10->f[0] + $rss10->f[0] - $rs10x->f[0] - 0 );
    $tpl->set( "money11", $rs11->f[0] + $rss11->f[0] - $rs11x->f[0] - 0 );
}
else
{
    $tpl->set( "money48", $rs48->f[0] - $rs48x->f[0] - 0 );
    $tpl->set( "money08", $rs8->f[0] - $rs8x->f[0] - 0 );
    $tpl->set( "money09", $rs9->f[0] - $rs9x->f[0] - 0 );
    $tpl->set( "money07", $rs7->f[0] - $rs7x->f[0] - 0 );
    $tpl->set( "money10", $rs10->f[0] - $rs10x->f[0] - 0 );
    $tpl->set( "money11", $rs11->f[0] - $rs11x->f[0] - 0 );
}
if ( $conf->get( "protect_start" ) == 0 )
{
    $tpl->set( "startnowdisable", "disabled" );
}
include_once( "class_6h/class.menu.php" );
$fieldArr = array( "open" => $open, "lotto_id" => $lotto_id, "split_id" => 1 );
$onlineMenu = new menu_6h( 12, $fieldArr );
$selectid = getvar( "select" ) == "" ? 0 : getvar( "select" );
$menuList = $onlineMenu->getMenu( $selectid );
$tpl->set( "menuList", $menuList );
unset( $onlineMenu );
$tpl->load( "main", "bnow3.htm" );
$tpl->set( "jslang", $g_conf['language'] );
$tpl->show( "main" );
$ui->footer();
?>